var baseurl = "/webapp/japword/";
document.observe("dom:loaded", function() {
	var pathname = window.location.pathname;
	var relativepath = pathname.substr(baseurl.length);
	
	if (relativepath == "index.html" || relativepath == '') {
	}

	localStorage.lastPage = relativepath;
	
});

function myLoadHandler(evt)
{
  if (evt.persisted) {
    alert('user returns to page from another tab');
    return;
  }
  alert('loading new page'+localStorage.testI);
}

function myUnloadHandler(evt)
{
  if (evt.persisted) {
    alert('user goes to new tab');
    return;
  }
  alert('user truly leaves the page');
  if (!localStorage.testI)
		localStorage.testI = 1;
	else
	localStorage.testI++;
}

if ("onpagehide" in window) {
  window.addEventListener("pageshow", myLoadHandler, false);
  window.addEventListener("pagehide", myUnloadHandler, false);
} else {
  window.addEventListener("load", myLoadHandler, false);
  window.addEventListener("unload", myUnloadHandler, false);
}